const formOption = {
    formSelector: '#register',
    submitSelector: '#submit',
    fieldsOpt: {
        realName: {
            selector: '#real-name',
            errorMsg: '姓名不符合规范',
            successMsg: '姓名OK了',
            rules:{
                reg: /^[\u4e00-\u9fa5]{2,6}/
            }
            
        },
        addr: {
            selector: '#addr',
            errorMsg: '你住在火星上吗？',
            successMsg: '确定你是地球人了',
            rules:{
                reg: /\w{4,}/
            }
            
        },
        email: {
            selector: '#email',
            errorMsg: '邮箱错误',
            successMsg: '邮箱OK了',
            rules:{
                reg: /^[A-Za-z0-9]\w+@\w{2,}\.[a-zA-Z]{2,4}/
            }
        },
        pwd1:{
            selector: '#pwd',
            errorMsg: '密码太弱鸡了',
            successMsg: '你各家千万不要搞忘了',
            rules:{
                reg: /^\w{6,20}/
            }  
        },
        pwd2:{
            selector: '#pwd2',
            errorMsg: {
                reg:'密码太弱鸡了',
                equal:'两次密码必须相等'
            },
            successMsg: '你各家千万不要搞忘了',
            rules:{
                reg: /^\w{6,20}/,
                equal:'pwd1'
            }  
        }
    },
    fieldSuccess:function(field, msg, element){
        element.parentElement.classList.add('success')
        element.parentElement.classList.remove('error')
        element.nextElementSibling.innerText = msg
    },
    fieldError:function(field, msg, element){
        element.parentElement.classList.remove('success')
        element.parentElement.classList.add('error')
        element.nextElementSibling.innerText = msg
        
    }, 
    formSuccess: function (valiRes) {
        console.log('验证成功')
    },
    //自定义表单验证成功失败回掉函数
    formError: function (valiRes) {
        console.log(valiRes)
        console.log('验证失败')
    }
}

const  vf = new ValidateForm(formOption)